﻿@{
    ViewBag.Title = "岗位管理";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}
<script language="javascript" type="text/javascript">

    //初始化部门列表
    function InitDepCombobox(id) {
        if (id == undefined) id = 0;
        $('#DepId').combobox({
            url: InitUrl.Dep + "?id=" + id,
            valueField: 'Id',
            textField: 'DepName'
        });
    }

    //初始化岗位
    function InitLevelCombobox(value) {
        if (value) {
            $('#ParentId').combobox({
                url: InitUrl.Level + value,
                valueField: 'LevelId',
                textField: 'LevelName'
            });
        }
    }



    //添加级别
    function addLevel() {
        InitDepCombobox();
        InitLevelCombobox();
        $('#dlg').dialog('open').dialog('setTitle', '新增');
        $('#fm').form('clear');
        url = '/BasicManage/AddLevel';
    }


    //编辑岗位信息
    function editLevel() {
        var row = $('#tt').tree('getSelected');
        if (row.attributes == null || row.attributes.isLevel != 1) {
            Helper.Show('请选择正确岗位来编辑!');
            return false;
        }
        $.post('/BasicManage/GetDepLevelModel', { levelId: row.id }, function (data) {
            InitDepCombobox();
            $('#dlg').dialog('open').dialog('setTitle', '编辑'); //
            $('#fm').form('load', data);
            url = "/BasicManage/EditLevel";
        });
    }

    //删除级别(岗位)树
    function delLevel() {
        var row = $('#tt').tree('getSelected');
        if (row.attributes == null || row.attributes.isLevel != 1) {
            Helper.Show('请选择正确岗位来删除!');
            return false;
        }
        $.messager.confirm('提示信息', '数据删除之后无法恢复,你确定要删除吗?', function (r) {
            if (r) {
                $.post('/BasicManage/DelLevel', { levelId: row.id }, function (json) {
                    Helper.Show(json.Msg);
                    if (json.Success) {
                        $('#tt').tree('reload'); // reload the user data
                    }
                });
            }
        });
    }

 
    function SaveLevel() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Success) {
                    $('#dlg').dialog('close'); 	// 关闭弹出层
                    $('#tt').tree('reload'); // reload the user data
                }
            }
        });
    }
</script>
<div id="tb" style="padding: 3px; height: auto; border: 1px solid #red; background-color: #00000;">
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addLevel()">添加</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editLevel()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-cut" plain="true" onclick="delLevel()">删除</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" title="弹出页面" data-options="iconCls:'icon-save'"
    closed="true" style="width: 400px; height: 300px; padding: 10px 20px" buttons="#dlg-buttons" modal="true">
    <div class="ftitle">
    </div>
    <form id="fm" method="post" novalidate>
        <input type="hidden" name="Id" value="" />
        <div class="fitem">
            <label>
                所属部门:</label>
            <input id="DepId" name="DepId" required="true" class="easyui-combobox" style="width: 173px; height: 30px;" />
        </div>
        <div class="fitem">
            <label>
                岗位名称:</label>
            <input name="LevelName" class="easyui-validatebox textbox" required="true" style="width: 173px; height: 30px;"  autocomplete="off"  />
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="SaveLevel()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
<div style="margin: 10px 0;">
</div>
<ul id="tt" class="easyui-tree" data-options="url:'/BasicManage/InitDepLevelTree',method:'post',animate:true,lines:true">
</ul>


